package com.java;

import com.java.support.orther.OrtherData;
import com.maxmind.geoip2.DatabaseReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;

import javax.servlet.MultipartConfigElement;
import java.io.File;
import java.io.IOException;

/**
 * 
 * @author peng.liang
 * @date 2017年8月14日
 * @time 下午5:00:19
 */
@SpringBootApplication
public class StratMain {
	@Autowired
	private OrtherData ortherData;

	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(StratMain.class);
	}

	public static void main(String[] args) throws Exception {
		SpringApplication.run(StratMain.class, args);
	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		// 单个文件最大
		factory.setMaxFileSize("102400KB"); // KB,MB
		/// 设置总上传数据总大小
		factory.setMaxRequestSize("1024000KB");
		return factory.createMultipartConfig();
	}

	@Bean
	public DatabaseReader getDatabaseReader() {
		//File database = new File("E:\\GeoLite2-City_20190312\\GeoLite2-City_20190312\\GeoLite2-City.mmdb");
		File database = new File(ortherData.getDatabaseFile());
		// 读取数据库内容
		DatabaseReader reader=null;
		try {
			reader = new DatabaseReader.Builder(database).build();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return reader;
	}
}
